<template>
	<view style="margin: 0px 0;">
		<van-cell title="报销状态" :value="dataObj.statusText" />
		<van-cell title="车辆牌照" :value="dataObj.cp" />
		<van-cell title="缴费类型" :value="dataObj.type" />
		<van-cell title="缴费时间" :value="dataObj.time" />
		<van-cell title="缴费金额" :value="dataObj.total" />
		<van-field label="费用说明" :value="dataObj.note" type="textarea" readonly :autosize="{minHeight:80}"
		  />
		  <view style="background-color: #fff;padding: 10px; 16px">
		  	<van-uploader
		  	  :file-list="fileList"
		  	  max-count="20"
			  disabled
			  :show-upload="false"
			  :deletable="false"
		  	  @after-read="afterRead"
		  	/>
		  </view>
		  
		  <view v-if="dataObj.status == 0" style="margin-top: 20px;">
		  	<van-button  @click="onDelRefound" custom-class="right-button" :color="secondaryColor" :square="true" size="normal" block>删除报销</van-button>
		  </view>
		<van-dialog id="van-dialog" />
		<van-toast id="van-toast" />
	</view>
</template>

<script>
	import utils from '@/common/utils.js'
	import Dialog from '@/wxcomponents/dialog/dialog'
	import Toast from '@/wxcomponents/toast/toast'
	export default {
		data() {
			return {
				secondaryColor: getApp().globalData.secondaryColor,
				fileList:[],
				dataObj:{}
			}
		},
		onLoad(options) {
			this.dataObj = JSON.parse(decodeURIComponent(options.data))
			this.fileList = this.dataObj.imgs.map(o => {
				return {url:`${utils.fileUrl}/${o}`}
			})
		},
		methods:{
			onDelRefound(){
				Dialog.confirm({
					title: '提示',
					message: '请确认是否删除此报销数据'
				}).then(async() => {
					try{
						const reqData = {
							token: uni.getStorageSync('userinfo').token,
							id: this.dataObj.id
						}
						uni.showLoading({
							title:'删除中...',
							mask:true
						})
						await utils.req('/reimbursement/delReimbursement', reqData)
						uni.navigateBack({
							delta:1
						})
					}catch(e){
						console.error(e)
						Toast(e.msg)
					}finally{
						uni.hideLoading()
					}
				}).catch(() => {
					// on cancel
				});
			}
		}
	}
</script>

<style lang="scss">

</style>
